/**  形状 和 颜色
 * 原本需要 3 * 3 的进行设计
 * 可以抽离为2个单独类解偶，3 + 3 任意一类扩展
*/

interface Color {
  showColor (shape: string): void
}

class White implements Color {
  showColor(shape: string): void {
    console.log('白色的' + shape)
  }
}

class Black implements Color {
  showColor(shape: string): void {
    console.log('黑色的' + shape)
  }
}

class Red implements Color {
  showColor(shape: string): void {
    console.log('红色的' + shape)
  }
}

abstract class Shape {
  color?: Color

  setColor(color: Color) {
    this.color = color
  }

  abstract draw(): void
}

class Circle extends Shape {
  draw(): void {
    this.color?.showColor('长方形')
  }
}
class Rangle extends Shape {
  draw(): void {
    this.color?.showColor('矩形')
  }
}

(function () {
  let white: Color = new White()
  let rangle: Shape = new Rangle()

  rangle.setColor(white)
  rangle.draw()
}())